package com.googlecode.jkorpos.lingpipe;

public class CharArray implements CharSequence {
	

	private char[] _array;
	private int _base;
	private int _length;

	public CharArray(char[] cs, int start, int end) {
		_array = cs;
		_base = start;
		_length = end - start;
	}

	public char charAt(int index) {
		if (_base + _length < index)
			throw new IndexOutOfBoundsException();
		return _array[_base + index];
	}

	public int length() {
		return _length;
	}

	public CharSequence subSequence(int start, int end) {
		return new CharArray(_array, _base + start, _base + end);
	}

	@Override
	public String toString() {
		return new String(_array, _base, _length);
	}
}
